package my.jwds.p476;

public class FindComplement {


    public static void main(String[] args) {
        FindComplement obj = new FindComplement();
        System.out.println(obj.findComplement(5));
    }

    public int findComplement(int num) {
        int index = 0;
        int temp = num;
        while(temp != 0){
            temp/=2;
            index++;
        }
        int max =index == 31 ? Integer.MAX_VALUE: (1 << index) -1;
        return max-num;
    }
}
